﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Blackbird.Core.Editable.Frames;

namespace Blackbird.Editors.Sample
{
    public static class SampleGenerator
    {
        public static EditableFrameset GenerateFrameset()
        {
            var frameset = new EditableFrameset();

            var textPen = new Pen(Brushes.Black, 1.0);
            var demoTypeFace = new Typeface("Consolas");
            var origin = new Point(48, 32);
            for (int i = 0; i < 32; i++)
            {
                var vis = new DrawingVisual();
                using (DrawingContext context = vis.RenderOpen())
                {
                    context.DrawRectangle(Brushes.Green, null, new Rect(64, 64, 127, 127));
                    var text = new FormattedText(i.ToString(CultureInfo.CurrentCulture), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                                                 demoTypeFace, 64.0, Brushes.Black);
                    context.DrawEllipse(Brushes.DarkGreen, textPen, new Point(64, 64), Math.Abs(16 - i)*4.0,
                                        Math.Abs(16 - i)*4.0);
                    context.DrawText(text, origin);
                }
                var target = new RenderTargetBitmap(256, 256, 96, 96, PixelFormats.Pbgra32);
                target.Render(vis);
                frameset.Add(new EditableFrame
                                 {
                                     BitmapSource = target,
                                     Index = i
                                 });
            }

            return frameset;
        }
    }
}